<template>
	<view>

		<view class='price'>
			<text class='txt'>当前余额：</text>
			<text class='number'>{{money}}元</text>
		</view>
		<view class='Tips'>（金额大于1元时才可提现）</view>
		<view class='input'>
			<input type='digit' v-model="cash_fee" placeholder='请输入提现金额' bindinput='setvalue' placeholder-class='colorccc'></input>
		</view>
		<button @click='submit' class='submit cu-btn round bg-green shadow-blur'>确 定</button>
		<view class="flex flex-direction align-start padding-lr-lg">
			<view class="text-bold text-lg margin-bottom-xs">温馨提醒：</view>
			<text class="text-left text-df margin-left-xs text-grey" style="color: #222;">
				1. 每日限提现一笔\n2. 避免小金额频繁转账，大于1.0元才能提现\n3. 为保证交易安全请先到认证中心进行认证\n4. 请维护准确支付宝信息，转账只使用支付宝\n5. 支付宝姓名获取方式：支付宝-我的-点击头像-个人信息-身份认证姓名\n6. 提现结果请点击查看余额明细，提现完成后请查看支付宝转账记录\n7. 提现将于次日24点之前到账
			</text>
		</view>
		<view class="detail" @click="onGoNext('./List/List')">查看余额明细 >></view>
		<buy-hint ref="isBuyHintPopup" top="50" title="提现成功">
			<view class="text-gray text-center">
				{{msg}}
			</view>
			<button @click="onCallBack" style="width: 200rpx;" class="cu-btn bg-green round shadow-blur margin-top-lg">确 定</button>
		</buy-hint>
		
		<accredit ref="showPicker" @userInfo="GetUserSuccess"></accredit>
	</view>
</template>

<script>
	import BuyHint from "@/components/BuyHint.vue"
	import userApi from "@/Api/User.js"
	import { toast } from "@/utils/util.js"
	
	export default {
		components: {
			BuyHint
		},
		computed: {
			userAccredit() {
				return this.$store.state.userAccredit;
			}
		},
		data() {
			return {
				money: 0.00,
				cash_fee: '',
				msg: ''
			};
		},
		onLoad(obj) {
			this.getUserData()
		},
		methods: {
			getUserData() {
				userApi.getUserData()
					.then(res=> this.money = res.money)
			},
			submit() {
				if (this.userAccredit) {
					 this.$refs.showPicker.show()
					 return
				}
				if(this.cash_fee != '' && this.cash_fee >= 1 ) {
					this.postWithdraw()
				} else {
					toast('提现金额必须大于1元')
				}
			},
			
			// 微信用户授权方法回调
			GetUserSuccess(e) {
				this.$refs.showPicker.close();
			},
			
			// 体现
			postWithdraw() {
				this.showLoading('提现中')
				userApi.postWithdraw(this.cash_fee)
					.then(res=> {
						this.hideLoading()
						this.cash_fee = ''
						this.msg = res.msg
						this.$refs.isBuyHintPopup.show()
						this.getUserData()
					})
			},
			
			onCallBack() {
				this.$refs.isBuyHintPopup.close()
			}
		}
	}
</script>

<style lang="scss">
	page {
		text-align: center;
		background-color: #fff;
	}

	.price {
		margin-top: 55rpx;
		font-size: 36rpx;
		color: #000;
		letter-spacing: 0;
		line-height: 50rpx;
	}

	.price .number {
		font-size: 42rpx;
		color: #FC4E11;
		letter-spacing: 0;
		line-height: 59rpx;
	}

	.Tips {
		font-size: 28rpx;
		color: #999;
		letter-spacing: 0;
		margin-top: 10rpx;
	}

	.input {
		margin-top: 120rpx;
		padding: 0 75rpx;
	}

	.input input {
		background: #fff;
		border: 1px solid #979797;
		border-radius: 47px;
		padding: 0 40rpx;
		text-align: left;
		font-size: 36rpx;
		height: 86rpx;
		line-height: 86rpx;
	}

	.colorccc {
		color: #ccc;
	}

	.submit {
		border-radius: 47px;
		width: 600rpx;
		height: 84rpx;
		line-height: 84rpx;
		color: #fff;
		font-size: 36rpx;
		text-align: center;
		margin: 70rpx auto;

	}

	.NoPrice {
		background: #999999;
	}
	
	.detail{
		position: absolute;
		bottom: 55rpx;
		left: 0;
		right: 0;
		margin: auto;
		font-size: 32rpx;
		color: #FF9910;
		letter-spacing: 0;
		text-align: center;
	}
</style>
